package com.an.springbean;

import java.time.LocalDateTime;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author 86171
 * 实现各种生命周期控制访问
 */
public class Car implements BeanFactoryAware,BeanNameAware,InitializingBean,DisposableBean{

	private String brand;
	private String color;
	private int maxSpeed;
	
	private BeanFactory beanFactory;
	private String beanName;
	
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		System.out.println("调用setBrand()方法设置属性");
		this.brand = brand;
	}
	
	public void introduce() {
		System.err.println("jieshao介绍Car：[brand=" + brand + ",color=" + color + ",maxSpeed=" + maxSpeed + "]");
	}
	
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		this.color = color;
	}
	public int getMaxSpeed() {
		return maxSpeed;
	}
	public void setMaxSpeed(int maxSpeed) {
		this.maxSpeed = maxSpeed;
	}
	public Car() {
		System.err.println("Car无参数构造函数" + LocalDateTime.now().toLocalTime());
	}
	@Override
	public void destroy() throws Exception {
		System.err.println("diao调用destroy方法");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
			System.out.println("afterPropertiesSet");
	}

	@Override
	public void setBeanName(String beanName) {
		System.err.println("调用setBeanName（）");
		this.beanName = beanName;	
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {

		System.err.println("调用setBeanFactory（）");
		this.beanFactory = beanFactory;
	}

	public void myInit() {
		System.err.println("dia调用init-method所指的方法，将maxSpeed设置为4000");
		this.maxSpeed = 4000;
	}
	
	public void myDestroy() {
		System.out.println("diao调用destroy-method所指的方法");
	}
}
